﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.RDLC

Partial Class DocSaleTakeUp
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session.Item("StaffId") Is Nothing Then
            Response.Redirect("default.aspx")
        End If

        If Not Page.IsPostBack Then

            CBEBack.ConfirmText = "You are about to navigate away from this page. " & vbCrLf & "Changes will be discard!"
            CBEDownload.ConfirmText = "All the changes will be saved before you download the document!"

            lblStaffUID.Text = Session.Item("StaffId").ToString
            lblStaffType.Text = Session.Item("StaffType").ToString

            getddlOpenFileRef()

            If Not Session("id") Is Nothing Then
                lblDocId.Text = Me.Session("id").ToString
                pnlEntry.Visible = True
                pnlPreview.Visible = False
                LoadEntry()
                pnlDetails.Visible = True
            Else
                pnlEntry.Visible = True
                pnlPreview.Visible = False
                pnlDetails.Visible = False
            End If
        End If
    End Sub

    Private Sub getddlOpenFileRef()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        'Only display records that pending signing, pending collection and completed. New, relist or renew's record will not display here.
        If lblStaffType.Text = "2" Then 'ren
            objDB.dbVariable.SQLString = "SELECT OpenFileRef FROM AW_SaleTransaction WHERE TransactorId=@TransactorId " & _
                                   "AND Status in ('1','2','3')"
            objDB.AddParameter("TransactorId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        Else
            'admin/boss
            objDB.dbVariable.SQLString = "SELECT OpenFileRef FROM AW_SaleTransaction WHERE Status in ('1','2','3')"
        End If

        objDB.FillData(TempDT, "AW_SaleTransaction", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        ddlOpenRefNo.DataSource = TempDT
        ddlOpenRefNo.DataTextField = "OpenFileRef"
        ddlOpenRefNo.DataValueField = "OpenFileRef"
        ddlOpenRefNo.DataBind()
        ddlOpenRefNo.Items.Insert(0, "-SELECT-")
        ddlOpenRefNo.Items(0).Value = ""
    End Sub

    Private Sub LoadEntry()
        Dim TempDT As New Data.DataTable
        TempDT = LoadDocSale()
        For Each dtrow As Data.DataRow In TempDT.Rows
            txtTitle.Text = dtrow.Item("DocSaleTitle").ToString
            lblTransactionId.Text = dtrow.Item("TransactionId").ToString
            If IsError(ddlOpenRefNo.SelectedValue = dtrow.Item("DocOpenRefNo").ToString) Then
                ddlOpenRefNo.Items.Insert(1, dtrow.Item("DocOpenRefNo").ToString)
                ddlOpenRefNo.Items(1).Value = dtrow.Item("DocOpenRefNo").ToString
                ddlOpenRefNo.Items(1).Selected = True
            Else
                ddlOpenRefNo.SelectedValue = dtrow.Item("DocOpenRefNo").ToString
            End If
            lblTransact.Text = dtrow.Item("Category").ToString
            lblTransactBy.Text = dtrow.Item("REN").ToString
            lblListBy.Text = dtrow.Item("Lister").ToString
            If dtrow.Item("DocDate").ToString = "" Then
                txtDate.Text = ""
            Else
                txtDate.Text = Format(dtrow.Item("DocDate"), "dd-MMM-yyyy")
            End If
            lblPremise.Text = dtrow.Item("Premise").ToString
            lblTransactedPrice.Text = String.Format("{0:#,##0.00}", dtrow.Item("TransactedPrice"))
            txtBalMonthChar.Text = dtrow.Item("BalMonthChar").ToString
            txtbalMonthInt.Text = String.Format("{0:#,##0.00}", dtrow.Item("BalMonthInt"))
            ddlModeOfPayment.SelectedValue = dtrow.Item("ModeOfPayment").ToString
            txtExtMonthChar.Text = dtrow.Item("ExMonthChar").ToString
            txtExtMonthInt.Text = String.Format("{0:#,##0.00}", dtrow.Item("ExMonthInt"))
            ddlWith.SelectedValue = dtrow.Item("WInterest").ToString
            txtInterest.Text = String.Format("{0:#,##0.00}", dtrow.Item("Interest"))
            If dtrow.Item("SPADate").ToString = "" Then
                lblDateSPA.Text = ""
            Else
                lblDateSPA.Text = Format(dtrow.Item("SPADate"), "dd-MMM-yyyy")
            End If
            txtRemarks.Text = dtrow.Item("Remarks").ToString
            lblVName.Text = dtrow.Item("VendorName").ToString
            lblVNRIC.Text = dtrow.Item("VendorNRIC").ToString
            lblVAddress.Text = dtrow.Item("VendorAddress").ToString
            lblVContacPerson.Text = dtrow.Item("VendorContactPerson").ToString
            lblVTel.Text = dtrow.Item("VendorTel").ToString
            lblVFax.Text = dtrow.Item("VendorFax").ToString
            lblVMobile.Text = dtrow.Item("VendorMobile").ToString
            lblCommission.Text = String.Format("{0:#,##0.00}", dtrow.Item("VendorComission"))
            lblVSCompany.Text = dtrow.Item("VendorSCompany").ToString
            lblVSAddress.Text = dtrow.Item("VendorSAddress").ToString
            lblVSContactPerson.Text = dtrow.Item("VendorSContactPerson").ToString
            lblVSTel.Text = dtrow.Item("VendorSTel").ToString
            lblVSFax.Text = dtrow.Item("VendorSFax").ToString
            lblVSMobile.Text = dtrow.Item("VendorSMobile").ToString
            lblPName.Text = dtrow.Item("PurcName").ToString
            lblPNRIC.Text = dtrow.Item("PurcNRIC").ToString
            lblPAddress.Text = dtrow.Item("PurcAddress").ToString
            lblPContactPerson.Text = dtrow.Item("PurcContactPerson").ToString
            lblPTelNo.Text = dtrow.Item("PurcTel").ToString
            lblPFaxNo.Text = dtrow.Item("PurcFax").ToString
            lblPMobile.Text = dtrow.Item("PurcMobile").ToString
            lblDisbursement.Text = dtrow.Item("PurcDisbursement").ToString
            lblPSCompany.Text = dtrow.Item("PurcSCompany").ToString
            lblPSAddress.Text = dtrow.Item("PurcSAddress").ToString
            lblPSContactPerson.Text = dtrow.Item("PurcSContactPerson").ToString
            lblPSTel.Text = dtrow.Item("PurcSTel").ToString
            lblPSFax.Text = dtrow.Item("PurcSFax").ToString
            lblPSMobile.Text = dtrow.Item("PurcSMobile").ToString
            txtOtherRemarks.Text = dtrow.Item("OtherRemarks").ToString
            lblUpdated.Text = "Last Updated By : " & dtrow.Item("CreateBy").ToString & " on " & Format(dtrow.Item("CreateDate"), "dd-MMM-yyyy")
        Next

    End Sub

    Private Function LoadDocSale() As Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT d.DocSaleTitle, d.DocOpenRefNo, d.TransactionId, d.Category, d.REN, d.Lister, d.DocDate, d.TransactedPrice, d.Premise, " & _
                                    "d.BalMonthChar, d.BalMonthInt, d.ModeOfPayment, d.ExMonthChar, d.ExMonthInt, " & _
                                    "d.WInterest, d.Interest, d.SPADate, d.Remarks, d.VendorName, d.VendorNRIC, d.VendorAddress, " & _
                                    "d.VendorContactPerson, d.VendorTel, d.VendorFax, d.VendorMobile, d.VendorComission, " & _
                                    "d.VendorSCompany, d.VendorSAddress, d.VendorSContactPerson, d.VendorSTel, d.VendorSFax, " & _
                                    "d.VendorSMobile, d.PurcName, d.PurcNRIC, d.PurcAddress, d.PurcContactPerson, d.PurcTel, " & _
                                    "d.PurcFax, d.PurcMobile, d.PurcDisbursement, d.PurcSCompany, d.PurcSAddress, d.PurcSContactPerson, " & _
                                    "d.PurcSTel, d.PurcSFax, d.PurcSMobile, d.OtherRemarks, ISNULL(d.UpdateDate, d.CreateDate) as CreateDate, " & _
                                    "ISNULL(u.Initial, c.Initial) as CreateBy, d.StatusDelete FROM AW_DocTakeUpSale d " & _
                                    "LEFT JOIN AW_Staff u ON d.UpdateBy = u.StaffId LEFT JOIN AW_Staff c ON " & _
                                    "d.CreateBy = c.StaffId WHERE DocSaleId=@DocSaleId"
        objDB.AddParameter("DocSaleId", Data.SqlDbType.UniqueIdentifier, New Guid(lblDocId.Text))
        objDB.FillData(TempDT, "DocTakeUpSale", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()
        Return TempDT
    End Function

    Protected Sub btnRefresh_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT ST.TransactionId, CASE ST.TransListType WHEN '1' THEN 'SR' WHEN '2' THEN 'SC' WHEN '3' " & _
                                    "THEN 'SL' WHEN '4' THEN 'SI' ELSE '' END as Category, tr.Name as REN, li.Name as Lister, " & _
                                    "p.PropertyId, p.UnitNumber + ', ' + r.Road + ', ' + l.Location + ', ' + s.State + ', ' + c.Country as 'Address', " & _
                                    "ST.TransactedPrice, ST.SNPDate, CASE ST.VendorType WHEN '1' THEN ST.VendorCompany WHEN '0' THEN ST.VendorName1 ELSE '' END as VendorName, " & _
                                    "CASE ST.VendorType WHEN '1' THEN ST.VendorCompanyNo WHEN '0' THEN ST.VendorNRIC1 ELSE '' END as VendorNo, " & _
                                    "ST.VendorAddress, ST.VendorContactPerson, ST.VendorPhone, ST.VendorFax, ST.VendorMobile, ST.VendorEmail, " & _
                                    "CASE ST.PurchaserType WHEN '1' THEN ST.PurchaserCompany WHEN '0' THEN ST.PurchaserName1 " & _
                                    "ELSE '' END as PurchaserName, CASE ST.PurchaserType WHEN '1' THEN ST.PurchaserCompanyNo WHEN '0' THEN ST.PurchaserNRIC1 ELSE '' END " & _
                                    "as PurchaserNo, ST.PurchaserAddress, ST.PurchaserContactPerson, ST.PurchaserPhone, ST.PurchaserMobile, " & _
                                    "ST.PurchaserFax, ST.PurchaserEmail, ST.AgencyFee, ST.DisbursementFee, ST.VendorSolicitorCompany, ST.VendorSolicitorAddress, " & _
                                    "ST.VendorSolicitorName, ST.VendorSolicitorPhone, ST.VendorSolicitorFax, ST.VendorSolicitorEmail, ST.PurchaserSolicitorCompany, " & _
                                    "ST.PurchaserSolicitorAddress, ST.PurchaserSolicitorName, ST.PurchaserSolicitorPhone, ST.PurchaserSolicitorFax, " & _
                                    "ST.PurchaserSolicitorEmail FROM AW_SaleTransaction ST LEFT JOIN AW_Property p ON " & _
                                    "ST.PropertyId=P.PropertyId LEFT JOIN AW_Road r ON p.RoadId=r.RoadId LEFT JOIN AW_Location l ON r.LocationId = l.LocationId " & _
                                    "LEFT JOIN AW_State s ON L.StateId=s.StateId LEFT JOIN AW_Country c ON s.CountryId=c.CountryId LEFT JOIN AW_Staff tr " & _
                                    "ON ST.TransactorId=tr.StaffId LEFT JOIN AW_Staff li ON ST.ListerId=li.StaffId WHERE ST.OpenFileRef=@OpenFileRef "
        objDB.AddParameter("OpenFileRef", Data.SqlDbType.NVarChar, ddlOpenRefNo.SelectedValue)
        objDB.FillData(TempDT, "AW_SaleTransaction", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        For Each dr As Data.DataRow In TempDT.Rows
            lblTransactionId.Text = dr.Item("TransactionId").ToString
            lblTransact.Text = dr.Item("Category").ToString
            lblTransactBy.Text = dr.Item("REN").ToString
            lblListBy.Text = dr.Item("Lister").ToString
            lblPremise.Text = dr.Item("Address").ToString
            lblTransactedPrice.Text = dr.Item("TransactedPrice").ToString
            If dr.Item("SNPDate").ToString = "" Then
                lblDateSPA.Text = ""
            Else
                lblDateSPA.Text = Format(dr.Item("SNPDate"), "dd-MMM-yyyy")
            End If
            lblVName.Text = dr.Item("VendorName").ToString
            lblVNRIC.Text = dr.Item("VendorNo").ToString
            lblVAddress.Text = dr.Item("VendorAddress").ToString
            lblVContacPerson.Text = dr.Item("VendorContactPerson").ToString
            lblVTel.Text = dr.Item("VendorPhone").ToString
            lblVFax.Text = dr.Item("VendorFax").ToString
            lblVMobile.Text = dr.Item("VendorMobile").ToString
            lblCommission.Text = String.Format("{0:#,##0.00}", dr.Item("AgencyFee"))
            lblPName.Text = dr.Item("PurchaserName").ToString
            lblPNRIC.Text = dr.Item("PurchaserNo").ToString
            lblPAddress.Text = dr.Item("PurchaserAddress").ToString
            lblPContactPerson.Text = dr.Item("PurchaserAddress").ToString
            lblPTelNo.Text = dr.Item("PurchaserPhone").ToString
            lblPFaxNo.Text = dr.Item("PurchaserFax").ToString
            lblPMobile.Text = dr.Item("PurchaserMobile").ToString
            lblDisbursement.Text = String.Format("{0:#,##0.00}", dr.Item("DisbursementFee"))
            lblVSCompany.Text = dr.Item("VendorSolicitorCompany").ToString
            lblVSAddress.Text = dr.Item("VendorSolicitorAddress").ToString
            lblVSContactPerson.Text = dr.Item("VendorSolicitorName").ToString
            lblVSTel.Text = dr.Item("VendorSolicitorPhone").ToString
            lblVSFax.Text = dr.Item("VendorSolicitorFax").ToString
            lblVSMobile.Text = dr.Item("VendorSolicitorEmail").ToString
            lblPSCompany.Text = dr.Item("PurchaserSolicitorCompany").ToString
            lblPSAddress.Text = dr.Item("PurchaserSolicitorAddress").ToString
            lblPSContactPerson.Text = dr.Item("PurchaserSolicitorName").ToString
            lblPSTel.Text = dr.Item("PurchaserSolicitorPhone").ToString
            lblPSFax.Text = dr.Item("PurchaserSolicitorFax").ToString
            lblPSMobile.Text = dr.Item("PurchaserSolicitorEmail").ToString
        Next
        pnlDetails.Visible = True
    End Sub

    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            Dim DocExId As String
            If lblDocId.Text = String.Empty Then
                objDB.dbVariable.SQLString = "INSERT INTO AW_DocTakeUpSale(DocSaleId, DocSaleTitle, DocOpenRefNo, TransactionId, Category, REN, Lister, " & _
                                            "DocDate, Premise, TransactedPrice, BalMonthChar, BalMonthInt, ModeOfPayment, " & _
                                            "ExMonthChar, ExMonthInt, WInterest, Interest, SPADate, Remarks, VendorName, " & _
                                            "VendorNRIC, VendorAddress, VendorContactPerson, VendorTel, VendorFax, VendorMobile, " & _
                                            "VendorComission, VendorSCompany, VendorSAddress, VendorSContactPerson, VendorSTel, " & _
                                            "VendorSFax, VendorSMobile, PurcName, PurcNRIC, PurcAddress, PurcContactPerson, PurcTel, " & _
                                            "PurcFax, PurcMobile, PurcDisbursement, PurcSCompany, PurcSAddress, PurcSContactPerson, " & _
                                            "PurcSTel, PurcSFax, PurcSMobile, OtherRemarks, CreateDate, CreateBy, UpdateDate, UpdateBy, StatusDelete) " & _
                                            "VALUES (@DocSaleId, @DocSaleTitle, @DocOpenRefNo, @TransactionId, @Category, @REN, @Lister, " & _
                                            "@DocDate, @Premise, @TransactedPrice, @BalMonthChar, @BalMonthInt, @ModeOfPayment, " & _
                                            "@ExMonthChar, @ExMonthInt, @WInterest, @Interest, @SPADate, @Remarks, @VendorName, " & _
                                            "@VendorNRIC, @VendorAddress, @VendorContactPerson, @VendorTel, @VendorFax, @VendorMobile, " & _
                                            "@VendorComission, @VendorSCompany, @VendorSAddress, @VendorSContactPerson, @VendorSTel, " & _
                                            "@VendorSFax, @VendorSMobile, @PurcName, @PurcNRIC, @PurcAddress, @PurcContactPerson, @PurcTel, " & _
                                            "@PurcFax, @PurcMobile, @PurcDisbursement, @PurcSCompany, @PurcSAddress, @PurcSContactPerson, " & _
                                            "@PurcSTel, @PurcSFax, @PurcSMobile, @OtherRemarks, @CreateDate, @CreateBy, @UpdateDate, @UpdateBy, @StatusDelete)"
                DocExId = Guid.NewGuid.ToString
                lblUpdated.Text = "Created By : " & GetName() & " on " & Format(Now(), "dd-MMM-yyyy")
                objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("UpdateBy", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            Else
                objDB.dbVariable.SQLString = "UPDATE AW_DocTakeUpSale SET DocSaleTitle=@DocSaleTitle, DocOpenRefNo=@DocOpenRefNo, TransactionId=@TransactionId, Category=@Category, " & _
                                            "REN=@REN, Lister=@Lister, DocDate=@DocDate, Premise=@Premise, TransactedPrice=@TransactedPrice, BalMonthChar=@BalMonthChar, " & _
                                            "BalMonthInt=@BalMonthInt, ModeOfPayment=@ModeOfPayment, ExMonthChar=@ExMonthChar, ExMonthInt=@ExMonthInt, " & _
                                            "WInterest=@WInterest, SPADate=@SPADate, Remarks=@Remarks, VendorName=@VendorName, VendorNRIC=@VendorNRIC, " & _
                                            "VendorAddress=@VendorAddress, VendorContactPerson=@VendorContactPerson, VendorTel=@VendorTel, VendorFax=@VendorFax, " & _
                                            "VendorMobile=@VendorMobile, VendorComission=@VendorComission, VendorSCompany=@VendorSCompany, VendorSAddress=@VendorSAddress, " & _
                                            "VendorSContactPerson=@VendorSContactPerson, VendorSTel=@VendorSTel, VendorSFax=@VendorSFax, VendorSMobile=@VendorSMobile, " & _
                                            "PurcName=@PurcName, PurcNRIC=@PurcNRIC, PurcAddress=@PurcAddress, PurcContactPerson=@PurcContactPerson, " & _
                                            "PurcTel=@PurcTel, PurcFax=@PurcFax, PurcMobile=@PurcMobile, PurcDisbursement=@PurcDisbursement, PurcSCompany=@PurcSCompany, " & _
                                            "PurcSAddress=@PurcSAddress, PurcSContactPerson=@PurcSContactPerson, PurcSTel=@PurcSTel, PurcSDFax=@PurcSFax, " & _
                                            "PurcSMobile=@PurcSMobile, OtherRemarks=@OtherRemarks, UpdateDate=@UpdateDate, UpdateBy=@UpdateBy WHERE DocSaleId=@DocSaleId"
                DocExId = lblDocId.Text.Trim
                lblUpdated.Text = "Last Updated By : " & GetName() & " on " & Format(Now(), "dd-MMM-yyyy")
                objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
                objDB.AddParameter("UpdateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
            End If
            objDB.AddParameter("DocSaleId", Data.SqlDbType.UniqueIdentifier, New Guid(DocExId))
            objDB.AddParameter("DocSaleTitle", Data.SqlDbType.NVarChar, txtTitle.Text.Trim.ToUpper)
            objDB.AddParameter("DocOpenRefNo", Data.SqlDbType.NVarChar, ddlOpenRefNo.SelectedValue)
            objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransactionId.Text))
            If lblTransact.Text = String.Empty Then
                objDB.AddParameter("Category", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Category", Data.SqlDbType.NVarChar, lblTransact.Text.Trim)
            End If
            If lblTransactBy.Text = String.Empty Then
                objDB.AddParameter("REN", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("REN", Data.SqlDbType.NVarChar, lblTransactBy.Text.Trim)
            End If
            If lblListBy.Text = String.Empty Then
                objDB.AddParameter("Lister", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Lister", Data.SqlDbType.NVarChar, lblListBy.Text.Trim)
            End If
            If txtDate.Text = String.Empty Then
                objDB.AddParameter("DocDate", Data.SqlDbType.DateTime, DBNull.Value)
            Else
                objDB.AddParameter("DocDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtDate.Text.Trim, "dd-MMM-yyyy", Nothing))
            End If
            If lblPremise.Text = String.Empty Then
                objDB.AddParameter("Premise", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Premise", Data.SqlDbType.NVarChar, lblPremise.Text.Trim)
            End If
            If lblTransactedPrice.Text = String.Empty Then
                objDB.AddParameter("TransactedPrice", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TransactedPrice", Data.SqlDbType.NVarChar, lblTransactedPrice.Text.Trim)
            End If
            If txtBalMonthChar.Text = String.Empty Then
                objDB.AddParameter("BalMonthChar", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("BalMonthChar", Data.SqlDbType.NVarChar, txtBalMonthChar.Text.Trim)
            End If
            If txtbalMonthInt.Text = String.Empty Then
                objDB.AddParameter("BalMonthInt", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("BalMonthInt", Data.SqlDbType.NVarChar, CDbl(txtbalMonthInt.Text))
            End If
            objDB.AddParameter("ModeOfPayment", Data.SqlDbType.NVarChar, ddlModeOfPayment.SelectedValue)
            If txtExtMonthChar.Text = String.Empty Then
                objDB.AddParameter("ExMonthChar", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("ExMonthChar", Data.SqlDbType.NVarChar, txtExtMonthChar.Text.Trim)
            End If
            If txtExtMonthInt.Text = String.Empty Then
                objDB.AddParameter("ExMonthInt", Data.SqlDbType.Decimal, DBNull.Value)
            Else
                objDB.AddParameter("ExMonthInt", Data.SqlDbType.Decimal, CDbl(txtExtMonthInt.Text.Trim))
            End If
            objDB.AddParameter("WInterest", Data.SqlDbType.NVarChar, ddlWith.SelectedValue)
            If txtInterest.Text = String.Empty Then
                objDB.AddParameter("Interest", Data.SqlDbType.Decimal, DBNull.Value)
            Else
                objDB.AddParameter("Interest", Data.SqlDbType.Decimal, CDbl(txtInterest.Text.Trim))
            End If
            If lblDateSPA.Text = String.Empty Then
                objDB.AddParameter("SPADate", Data.SqlDbType.DateTime, DBNull.Value)
            Else
                objDB.AddParameter("SPADate", Data.SqlDbType.DateTime, DateTime.ParseExact(lblDateSPA.Text, "dd-MMM-yyyy", Nothing))
            End If
            If txtRemarks.Text = String.Empty Then
                objDB.AddParameter("Remarks", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Remarks", Data.SqlDbType.NVarChar, txtRemarks.Text)
            End If
            If lblVName.Text = String.Empty Then
                objDB.AddParameter("VendorName", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorName", Data.SqlDbType.NVarChar, lblVName.Text)
            End If
            If lblVNRIC.Text = String.Empty Then
                objDB.AddParameter("VendorNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorNRIC", Data.SqlDbType.NVarChar, lblVNRIC.Text)
            End If
            If lblVAddress.Text = String.Empty Then
                objDB.AddParameter("VendorAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorAddress", Data.SqlDbType.NVarChar, lblVAddress.Text)
            End If
            If lblVContacPerson.Text = String.Empty Then
                objDB.AddParameter("VendorContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorContactPerson", Data.SqlDbType.NVarChar, lblVContacPerson.Text)
            End If
            If lblVTel.Text = String.Empty Then
                objDB.AddParameter("VendorTel", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorTel", Data.SqlDbType.NVarChar, lblVTel.Text)
            End If
            If lblVFax.Text = String.Empty Then
                objDB.AddParameter("VendorFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorFax", Data.SqlDbType.NVarChar, lblVFax.Text)
            End If
            If lblVMobile.Text = String.Empty Then
                objDB.AddParameter("VendorMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorMobile", Data.SqlDbType.NVarChar, lblVMobile.Text)
            End If
            If lblCommission.Text = String.Empty Then
                objDB.AddParameter("VendorComission", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorComission", Data.SqlDbType.NVarChar, lblCommission.Text)
            End If
            If lblVSCompany.Text = String.Empty Then
                objDB.AddParameter("VendorSCompany", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSCompany", Data.SqlDbType.NVarChar, lblVSCompany.Text)
            End If
            If lblVSAddress.Text = String.Empty Then
                objDB.AddParameter("VendorSAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSAddress", Data.SqlDbType.NVarChar, lblVSAddress.Text)
            End If
            If lblVSContactPerson.Text = String.Empty Then
                objDB.AddParameter("VendorSContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSContactPerson", Data.SqlDbType.NVarChar, lblVSContactPerson.Text)
            End If
            If lblVSTel.Text = String.Empty Then
                objDB.AddParameter("VendorSTel", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSTel", Data.SqlDbType.NVarChar, lblVSTel.Text)
            End If
            If lblVSFax.Text = String.Empty Then
                objDB.AddParameter("VendorSFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSFax", Data.SqlDbType.NVarChar, lblVSFax.Text)
            End If
            If lblVSMobile.Text = String.Empty Then
                objDB.AddParameter("VendorSMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSMobile", Data.SqlDbType.NVarChar, lblVSMobile.Text)
            End If
            If lblPName.Text = String.Empty Then
                objDB.AddParameter("PurcName", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcName", Data.SqlDbType.NVarChar, lblPName.Text)
            End If
            If lblPNRIC.Text = String.Empty Then
                objDB.AddParameter("PurcNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcNRIC", Data.SqlDbType.NVarChar, lblPNRIC.Text)
            End If
            If lblPAddress.Text = String.Empty Then
                objDB.AddParameter("PurcAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcAddress", Data.SqlDbType.NVarChar, lblPAddress.Text)
            End If
            If lblPContactPerson.Text = String.Empty Then
                objDB.AddParameter("PurcContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcContactPerson", Data.SqlDbType.NVarChar, lblPContactPerson.Text)
            End If
            If lblPTelNo.Text = String.Empty Then
                objDB.AddParameter("PurcTel", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcTel", Data.SqlDbType.NVarChar, lblPTelNo.Text)
            End If
            If lblPFaxNo.Text = String.Empty Then
                objDB.AddParameter("PurcFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcFax", Data.SqlDbType.NVarChar, lblPFaxNo.Text)
            End If
            If lblPMobile.Text = String.Empty Then
                objDB.AddParameter("PurcMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcMobile", Data.SqlDbType.NVarChar, lblPMobile.Text)
            End If
            If lblDisbursement.Text = String.Empty Then
                objDB.AddParameter("PurcDisbursement", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcDisbursement", Data.SqlDbType.NVarChar, lblDisbursement.Text)
            End If
            If lblPSCompany.Text = String.Empty Then
                objDB.AddParameter("PurcSCompany", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcSCompany", Data.SqlDbType.NVarChar, lblPSCompany.Text)
            End If
            If lblPSAddress.Text = String.Empty Then
                objDB.AddParameter("PurcSAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcSAddress", Data.SqlDbType.NVarChar, lblPSAddress.Text)
            End If
            If lblPSContactPerson.Text = String.Empty Then
                objDB.AddParameter("PurcSContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcSContactPerson", Data.SqlDbType.NVarChar, lblPSContactPerson.Text)
            End If
            If lblPSTel.Text = String.Empty Then
                objDB.AddParameter("PurcSTel", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcSTel", Data.SqlDbType.NVarChar, lblPSTel.Text)
            End If
            If lblPSFax.Text = String.Empty Then
                objDB.AddParameter("PurcSFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcSFax", Data.SqlDbType.NVarChar, lblPSFax.Text)
            End If
            If lblPSMobile.Text = String.Empty Then
                objDB.AddParameter("PurcSMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurcSMobile", Data.SqlDbType.NVarChar, lblPSMobile.Text)
            End If
            If txtOtherRemarks.Text = String.Empty Then
                objDB.AddParameter("OtherRemarks", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("OtherRemarks", Data.SqlDbType.NVarChar, txtOtherRemarks.Text)
            End If
            objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
            objDB.AddParameter("CreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
            objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
            objDB.ExecuteQuery()
            objDB.DbTransCommit()
            objDB.CloseConnection()
            lblDocId.Text = DocExId
        Catch ex As Exception
            objDB.DbTransRollback()
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.CloseConnection()
            End If
            lblMsgError.Text = ex.Message
            divError.Visible = True
        End Try
    End Sub

    Private Function GetName() As String
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable
        Dim StaffName As String = String.Empty

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT Name FROM AW_Staff WHERE StaffId=@StaffId"
        objDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        objDB.FillData(TempDT, "AW_Staff", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        For Each dtrow As Data.DataRow In TempDT.Rows
            If dtrow.Item("Name").ToString <> "" Then
                StaffName = dtrow.Item("Name").ToString
            End If
        Next

        Return StaffName
    End Function

    Protected Sub btnPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPreview.Click
        pnlEntry.Visible = False
        pnlPreview.Visible = True

        Dim TempDT As New Data.DataTable
        Dim CommissionDT As New Data.DataTable
        Dim GrandTotal As Decimal = 0

        'TempDT = LoadDocSale()
        DeclareColumnTempDT(TempDT)
        Dim MyRow As Data.DataRow
        MyRow = TempDT.NewRow()
        MyRow(0) = txtTitle.Text.Trim.ToUpper
        MyRow(1) = ddlOpenRefNo.SelectedValue
        MyRow(2) = lblTransactionId.Text.Trim
        MyRow(3) = lblTransact.Text.Trim
        MyRow(4) = lblTransactBy.Text.Trim
        MyRow(5) = lblListBy.Text.Trim
        If txtDate.Text = String.Empty Then
            MyRow(6) = DBNull.Value
        Else
            MyRow(6) = DateTime.ParseExact(txtDate.Text.Trim, "dd-MMM-yyyy", Nothing)
        End If
        MyRow(7) = lblPremise.Text.Trim
        If lblTransactedPrice.Text = String.Empty Then
            MyRow(8) = DBNull.Value
        Else
            MyRow(8) = CDbl(lblTransactedPrice.Text.Trim)
        End If
        MyRow(9) = txtBalMonthChar.Text.Trim
        If txtbalMonthInt.Text = String.Empty Then
            MyRow(10) = DBNull.Value
        Else
            MyRow(10) = CDbl(txtbalMonthInt.Text.Trim)
        End If
        MyRow(11) = ddlModeOfPayment.SelectedValue
        MyRow(12) = txtExtMonthChar.Text.Trim
        If txtExtMonthInt.Text = String.Empty Then
            MyRow(13) = DBNull.Value
        Else
            MyRow(13) = CDbl(txtExtMonthInt.Text.Trim)
        End If
        MyRow(14) = ddlWith.SelectedValue
        If txtInterest.Text = String.Empty Then
            MyRow(15) = DBNull.Value
        Else
            MyRow(15) = CDbl(txtInterest.Text.Trim)
        End If
        If lblDateSPA.Text = String.Empty Then
            MyRow(16) = DBNull.Value
        Else
            MyRow(16) = DateTime.ParseExact(lblDateSPA.Text.Trim, "dd-MMM-yyyy", Nothing)
        End If
        MyRow(17) = txtRemarks.Text.Trim
        MyRow(18) = lblVName.Text.Trim
        MyRow(19) = lblVNRIC.Text.Trim
        MyRow(20) = lblVAddress.Text.Trim
        MyRow(21) = lblVContacPerson.Text.Trim
        MyRow(22) = lblVTel.Text.Trim
        MyRow(23) = lblVFax.Text.Trim
        MyRow(24) = lblVMobile.Text.Trim
        If lblCommission.Text = String.Empty Then
            MyRow(25) = DBNull.Value
        Else
            MyRow(25) = CDbl(lblCommission.Text.Trim)
        End If
        MyRow(26) = lblVSCompany.Text.Trim
        MyRow(27) = lblVSAddress.Text.Trim
        MyRow(28) = lblVSContactPerson.Text.Trim
        MyRow(29) = lblVSTel.Text.Trim
        MyRow(30) = lblVSFax.Text.Trim
        MyRow(31) = lblVSMobile.Text.Trim
        MyRow(32) = lblPName.Text.Trim
        MyRow(33) = lblPNRIC.Text.Trim
        MyRow(34) = lblPAddress.Text.Trim
        MyRow(35) = lblPContactPerson.Text.Trim
        MyRow(36) = lblPTelNo.Text.Trim
        MyRow(37) = lblPFaxNo.Text.Trim
        MyRow(38) = lblPMobile.Text.Trim
        If lblDisbursement.Text = String.Empty Then
            MyRow(39) = DBNull.Value
        Else
            MyRow(39) = CDbl(lblDisbursement.Text.Trim)
        End If
        MyRow(40) = lblPSCompany.Text.Trim
        MyRow(41) = lblPSAddress.Text.Trim
        MyRow(42) = lblPSContactPerson.Text.Trim
        MyRow(43) = lblPSTel.Text.Trim
        MyRow(44) = lblPSFax.Text.Trim
        MyRow(45) = lblPSMobile.Text.Trim
        MyRow(46) = txtOtherRemarks.Text.Trim
        MyRow(47) = GetName()
        MyRow(48) = Now()
        TempDT.Rows.Add(MyRow)

        If TempDT IsNot Nothing Then
            Dim objRDLC As New RDLC("report/rptDocSaleTakeUp.rdlc", "DocSaleTakeUp")
            TempDT.TableName = "dsDocSaleTakeUp_AW_DocSaleTakeUp"
            objRDLC.AddDatabase(TempDT)
            ReportViewer1.LocalReport.DataSources.Clear()
            ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource(TempDT.TableName, TempDT))
            ReportViewer1.LocalReport.Refresh()
        End If
    End Sub

    Private Sub DeclareColumnTempDT(ByVal MyDT As Data.DataTable)
        Dim DocSaleTitle As Data.DataColumn = New Data.DataColumn("DocSaleTitle")
        DocSaleTitle.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(DocSaleTitle)
        Dim DocOpenRefNo As Data.DataColumn = New Data.DataColumn("DocOpenRefNo")
        DocOpenRefNo.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(DocOpenRefNo)
        Dim TransactionId As Data.DataColumn = New Data.DataColumn("TransactionId")
        TransactionId.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TransactionId)
        Dim Category As Data.DataColumn = New Data.DataColumn("Category")
        Category.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Category)
        Dim REN As Data.DataColumn = New Data.DataColumn("REN")
        REN.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(REN)
        Dim Lister As Data.DataColumn = New Data.DataColumn("Lister")
        Lister.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Lister)
        Dim DocDate As Data.DataColumn = New Data.DataColumn("DocDate")
        DocDate.DataType = System.Type.GetType("System.DateTime")
        MyDT.Columns.Add(DocDate)
        Dim Premise As Data.DataColumn = New Data.DataColumn("Premise")
        Premise.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Premise)
        Dim TransactedPrice As Data.DataColumn = New Data.DataColumn("TransactedPrice")
        TransactedPrice.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(TransactedPrice)
        Dim BalMonthChar As Data.DataColumn = New Data.DataColumn("BalMonthChar")
        BalMonthChar.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(BalMonthChar)
        Dim BalMonthInt As Data.DataColumn = New Data.DataColumn("BalMonthInt")
        BalMonthInt.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(BalMonthInt)
        Dim ModeOfPayment As Data.DataColumn = New Data.DataColumn("ModeOfPayment")
        ModeOfPayment.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(ModeOfPayment)
        Dim ExMonthChar As Data.DataColumn = New Data.DataColumn("ExMonthChar")
        ExMonthChar.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(ExMonthChar)
        Dim ExMonthInt As Data.DataColumn = New Data.DataColumn("ExMonthInt")
        ExMonthInt.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(ExMonthInt)
        Dim WInterest As Data.DataColumn = New Data.DataColumn("WInterest")
        WInterest.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(WInterest)
        Dim Interest As Data.DataColumn = New Data.DataColumn("Interest")
        Interest.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(Interest)
        Dim SPADate As Data.DataColumn = New Data.DataColumn("SPADate")
        SPADate.DataType = System.Type.GetType("System.DateTime")
        MyDT.Columns.Add(SPADate)
        Dim Remarks As Data.DataColumn = New Data.DataColumn("Remarks")
        Remarks.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Remarks)
        Dim VendorName As Data.DataColumn = New Data.DataColumn("VendorName")
        VendorName.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorName)
        Dim VendorNRIC As Data.DataColumn = New Data.DataColumn("VendorNRIC")
        VendorNRIC.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorNRIC)
        Dim VendorAddress As Data.DataColumn = New Data.DataColumn("VendorAddress")
        VendorAddress.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorAddress)
        Dim VendorContactPerson As Data.DataColumn = New Data.DataColumn("VendorContactPerson")
        VendorContactPerson.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorContactPerson)
        Dim VendorTel As Data.DataColumn = New Data.DataColumn("VendorTel")
        VendorTel.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorTel)
        Dim VendorFax As Data.DataColumn = New Data.DataColumn("VendorFax")
        VendorFax.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorFax)
        Dim VendorMobile As Data.DataColumn = New Data.DataColumn("VendorMobile")
        VendorMobile.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorMobile)
        Dim VendorComission As Data.DataColumn = New Data.DataColumn("VendorComission")
        VendorComission.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(VendorComission)
        Dim VendorSCompany As Data.DataColumn = New Data.DataColumn("VendorSCompany")
        VendorSCompany.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorSCompany)
        Dim VendorSAddress As Data.DataColumn = New Data.DataColumn("VendorSAddress")
        VendorSAddress.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorSAddress)
        Dim VendorSContactPerson As Data.DataColumn = New Data.DataColumn("VendorSContactPerson")
        VendorSContactPerson.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorSContactPerson)
        Dim VendorSTel As Data.DataColumn = New Data.DataColumn("VendorSTel")
        VendorSTel.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorSTel)
        Dim VendorSFax As Data.DataColumn = New Data.DataColumn("VendorSFax")
        VendorSFax.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorSFax)
        Dim VendorSMobile As Data.DataColumn = New Data.DataColumn("VendorSMobile")
        VendorSMobile.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(VendorSMobile)
        Dim PurcName As Data.DataColumn = New Data.DataColumn("PurcName")
        PurcName.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcName)
        Dim PurcNRIC As Data.DataColumn = New Data.DataColumn("PurcNRIC")
        PurcNRIC.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcNRIC)
        Dim PurcAddress As Data.DataColumn = New Data.DataColumn("PurcAddress")
        PurcAddress.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcAddress)
        Dim PurcContactPerson As Data.DataColumn = New Data.DataColumn("PurcContactPerson")
        PurcContactPerson.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcContactPerson)
        Dim PurcTel As Data.DataColumn = New Data.DataColumn("PurcTel")
        PurcTel.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcTel)
        Dim PurcFax As Data.DataColumn = New Data.DataColumn("PurcFax")
        PurcFax.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcFax)
        Dim PurcMobile As Data.DataColumn = New Data.DataColumn("PurcMobile")
        PurcMobile.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcMobile)
        Dim PurcDisbursement As Data.DataColumn = New Data.DataColumn("PurcDisbursement")
        PurcDisbursement.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(PurcDisbursement)
        Dim PurcSCompany As Data.DataColumn = New Data.DataColumn("PurcSCompany")
        PurcSCompany.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcSCompany)
        Dim PurcSAddress As Data.DataColumn = New Data.DataColumn("PurcSAddress")
        PurcSAddress.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcSAddress)
        Dim PurcSContactPerson As Data.DataColumn = New Data.DataColumn("PurcSContactPerson")
        PurcSContactPerson.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcSContactPerson)
        Dim PurcSTel As Data.DataColumn = New Data.DataColumn("PurcSTel")
        PurcSTel.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcSTel)
        Dim PurcSFax As Data.DataColumn = New Data.DataColumn("PurcSFax")
        PurcSFax.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcSFax)
        Dim PurcSMobile As Data.DataColumn = New Data.DataColumn("PurcSMobile")
        PurcSMobile.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PurcSMobile)
        Dim OtherRemarks As Data.DataColumn = New Data.DataColumn("OtherRemarks")
        OtherRemarks.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(OtherRemarks)
        Dim CreateBy As Data.DataColumn = New Data.DataColumn("CreateBy")
        CreateBy.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(CreateBy)
        Dim CreateDate As Data.DataColumn = New Data.DataColumn("CreateDate")
        CreateDate.DataType = System.Type.GetType("System.DateTime")
        MyDT.Columns.Add(CreateDate)
    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        If Session("Back") Is Nothing Then
            Response.Redirect("Documentation.aspx")
        Else
            Dim strBack As String = Session("Back").ToString
            Dim arr() As String = strBack.Split("ڡ")
            Response.Redirect(arr(0).ToString)
        End If
    End Sub

    Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownload.Click
        Dim TempDT As New Data.DataTable

        BtnSave_Click(sender, e)

        Dim CurrentUser As String = GetName()
        Dim PrintStr As String = "Printed by " & CurrentUser & " on " & Format(Now(), "dd-MMM-yyyy")

        TempDT = LoadDocSale()

        If TempDT IsNot Nothing Then
            Dim objRDLC As New RDLC("report/rptDocSaleTakeUp.rdlc", "DocSaleTakeUp")
            TempDT.TableName = "dsDocSaleTakeUp_AW_DocSaleTakeUp"
            objRDLC.AddDatabase(TempDT)
            objRDLC.AddParameter("PrintStr", PrintStr)
            objRDLC.ExportReport(RDLC.ExportTypeFormat.PDF, HttpContext.Current)
        End If
    End Sub

    Protected Sub btnBackEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBackEntry.Click
        pnlEntry.Visible = True
        pnlPreview.Visible = False
    End Sub
End Class
